<?php
/**
 * Created by PhpStorm.
 * User: Sixstar-Peter
 * Date: 2019/4/13
 * Time: 20:48
 */

//function coro(){
//
//    sleep(2);
//
//}
//
//coro();
//
//coro();
//
//coro();

//1.在某个特定的状态主动让出cpu的执行权限(中断执行)
//2.一旦程序状态改变,能够恢复程序的执行


////max(mysql,file,api);
//Swoole\Coroutine::create(function (){
//    Co::sleep(4); //调用api
//    echo "peter1".PHP_EOL;
//});
//
//
//go(function (){
//    Co::sleep(6); //读取文件
//    //协程空间
//    echo "peter2".PHP_EOL;
//});
//
//go(function (){
//    Co::sleep(3); //查询mysql
//    //协程空间
//    echo "peter3".PHP_EOL;
//});
//
//go(function (){
//    Co::sleep(3); //查询mysql
//    //协程空间
//    echo "peter3".PHP_EOL;
//});
//
//go(function (){
//    Co::sleep(3); //查询mysql
//    //协程空间
//    echo "peter3".PHP_EOL;
//});
//
//echo "是否是异步";
//


go(function () {
    $cli = new Swoole\Coroutine\Http\Client('47.98.147.49', 80);
    $cli->setHeaders([
        'Host' => "localhost",
        "User-Agent" => 'Chrome/49.0.2587.3',
        'Accept' => 'text/html,application/xhtml+xml,application/xml',
        'Accept-Encoding' => 'gzip',
    ]);
    $cli->get('/index.php');
    echo $cli->body;
    $cli->close();
});

go(function () {
    $cli = new Swoole\Coroutine\Http\Client('47.98.147.49', 80);
    $cli->setHeaders([
        'Host' => "localhost",
        "User-Agent" => 'Chrome/49.0.2587.3',
        'Accept' => 'text/html,application/xhtml+xml,application/xml',
        'Accept-Encoding' => 'gzip',
    ]);
    $cli->get('/index.php');
    echo $cli->body;
    $cli->close();
});